package com.study.common.baidu.map;

import com.study.common.baidu.map.domain.LbsVo;
import com.study.common.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LBSUtils {
    @Autowired
    private BaiduLbs baiduLbs;

    @Autowired
    private GoogleLbs googleLbs;


    private String mapType = "google";

    /**
     * 物理地址转化
     * @Title: toAddress
     * @Description: TODO
     * @author: 许智皓
     * @date: 2021年8月2日 上午10:03:46
     * @version: V1.0
     * @param lng 经度
     * @param lat 纬度
     * @param mapType 地图类型，google,baidu,amap,tx
     * @param languageIdIden
     * @return String
     *
     * @updateDate:
     * @update:
     */
    public LbsVo toAddress(double lng, double lat, String mapType, String languageIdIden) {

        switch (mapType) {

            case "google"://	google
                return googleLbs.getGoogleAddress(lng, lat, languageIdIden);

            case "baidu"://	baidu
                return baiduLbs.getBaiduAddressLanguage(lng, lat, languageIdIden);

        }
        LbsVo dto = new LbsVo();
        dto.setFormattedAddress(Constants.STR_NULL);
        dto.setLocality(Constants.STR_NULL);
        return dto;
    }

    public LbsVo toAddress(double lng,double lat, String languageIdIden) {



        switch (mapType) {

            case "google"://	google
                return googleLbs.getGoogleAddress(lng, lat, languageIdIden);

            case "baidu"://	baidu
                return baiduLbs.getBaiduAddressLanguage(lng, lat, languageIdIden);

        }

        LbsVo dto = new LbsVo();
        dto.setFormattedAddress(Constants.STR_NULL);
        dto.setLocality(Constants.STR_NULL);
        return dto;
    }


    public LbsVo toLatLng(double lng, double lat) {

        switch (mapType) {

            case "google"://	google
                return googleLbs.getGoogleAddress(lng, lat, "en");

            case "baidu"://	baidu
                return baiduLbs.getBaiduLatLng(lng, lat);

        }

        LbsVo dto = new LbsVo();
        dto.setFormattedAddress(Constants.FAIL);
        dto.setLocality(Constants.STR_NULL);
        dto.setLat(0.00);
        dto.setLng(0.00);
        return dto;
    }


}
